<?php
/**
 * User: 云喵
 * Agreement: 禁止使用本软件（系统）用于任何违法违规业务或项目,造成的任何法律后果允由使用者（或运营者）承担
 * Date: 2021/3/3
 * Time: 14:34
 */
namespace app\common\controller;
use think\Db;
use think\Controller;

class mq_gqqyjk extends Controller
{
    public function getReturn($code = 1, $data = "成功", $json = null)
    {
        return array("code" => $code, "data" => $data, "json" => $json);
    }
    
    public function cehsald($atad)//监控回调
    {
        $sz = Db::name("pay_sz")->find();
        $row = Db::name("pay_gfg")->where("pid", $atad['pid'])->where("mid",$atad['mid'])->find();
        $res = get_curl("https://im.qq.com/index",0,0,$row['ck'],0,"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Safari/537.36 Core/1.70.3870.400 QQBrowser/10.8.4405.400");
        $uin = getSubstr($res, '"uin":', ',"avatar"');
        $cache = tohc('mq_gqqyjk');//通道缓存
        $res = $cache->get($uin);
        if(!$res){
            return $this->getReturn(-1,'获取云端订单失败', $atad); 
        }
        $json = json_decode($res,TRUE);
        if($json['code']=="1"){
            if($json['data']['data']){
                foreach ($json['data']['data'] as $json) {
                    if($json['type']=='转账收入'){
                        if(strtotime($json['pay_date']) > $atad['create_date']){
                            if($json['pay_id']!=$atad['pay_id'] and $json['money']==$atad['price']){
                                $rof = Db::name("pay_order")->where("pid",$atad['pid'])->where("price",$json['money'])->where("order_id",$atad['order_id'])->where("state",1)->update(array("pay_id"=>$json['pay_id']));
                                if($rof){
                                    return $this->getReturn(1,'交易成功', $atad);
                                }else{
                                    return $this->getReturn(-1,'交易失败', $atad);
                                }
                            }
                        }else{
                            return $this->getReturn(-1,'交易失败', $atad);
                        }
                    }
                }
            }else{
                return $this->getReturn(-1,'交易失败', $atad);
            }
        }else{
           return $this->getReturn(-1,$json['msg'], $atad); 
        }
    }
    
    public function fukyem($data)//支付页面
    {
        $sz = Db::name("pay_sz")->find();
        $atad= Db::name("pay_gfg")->where("pid", $data['pid'])->where("mid", $data['mid'])->find();
        $user = Db::name("pay_user")->where("id", $data['pid'])->find();
        $data['timeOut'] = $user['bug_close'];//订单有效期
        
        if($data['type']=='qq'){//QQ
            $data['money'] = $data['price'];//实际金额
            $data['src'] = url('pay/enQrcode').'?url='.$data['mid_url'];//二维码
            $data['mid_url'] = $data['mid_json'];//H5转跳链接
            // 模板变量赋值
            $data['luji'] = '../../static/pay/pay_'.$sz['web_pay'];//模板路径
            $this->assign('data',$data);
            return $this->fetch('pay/pay_'.$sz['web_pay'].'/index');
        }
    }
    
    public function exec($atad,$money,$type)
    {
        $res = get_curl("https://im.qq.com/index",0,0,$atad['ck'],0,"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Safari/537.36 Core/1.70.3870.400 QQBrowser/10.8.4405.400");
	    $uin = getSubstr($res, '"uin":', ',"avatar"');
	    if($uin==0){
	        return $this->getReturn(-1, $atad['typec_name']."账号Cookie已过期");
	    }else{
	        $atad['data'] = $uin;//通道监控数据
            $atad['pay_id'] = time();//通道订单号
            $atad['mid_url'] = urlencode($atad['zhanghao']);//通道二维码
            return $this->getReturn(1, $atad, $atad['data']);
        }
    }
    
}